using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using System.Web;
using System.IO;
using Deepcode.Flux.Core.Data;
using Deepcode.Flux.Core.Services.FileSystem.Comparers;

namespace Deepcode.Flux.Core.Services.FileSystem
{
	/// <summary>
	/// Provides an object for sorting lists of FileInfo's
	/// </summary>
	public class FileSortService
	{
		/// <summary>
		/// Sorts the list provided by the expression and direction requested
		/// </summary>
		/// <param name="input"></param>
		/// <param name="Expression"></param>
		/// <param name="Direction"></param>
		/// <returns></returns>
		public List<System.IO.FileInfo> SortData(List<System.IO.FileInfo> input, string Expression, DataSortDirection Direction)
		{
			string Exp = Expression.ToUpper();
			switch (Exp)
			{
				case "NAME":
					if( Direction == DataSortDirection.ASCENDING )
						input.Sort( new FileInfoNameASCComparer() );
					if( Direction == DataSortDirection.DESCENDING )
						input.Sort( new FileInfoNameDESCComparer() );
					break;
				case "LENGTH":
					if (Direction == DataSortDirection.ASCENDING)
						input.Sort(new FileInfoLengthASCComparer());
					if (Direction == DataSortDirection.DESCENDING)
						input.Sort(new FileInfoLengthDESCComparer());
					break;
				case "EXTENSION":
					if (Direction == DataSortDirection.ASCENDING)
						input.Sort(new FileInfoExtensionASCComparer());
					if (Direction == DataSortDirection.DESCENDING)
						input.Sort(new FileInfoExtensionDESCComparer());
					break;
			}
			return input;
		}
	}
}
